import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import p003 from './p003';
import p005 from './p005';
interface Iparam extends Event {
	page_no: number;
}
export default async function a001(fd: IFeidaoAiBrowserComponent, e: Iparam) {
	// todo 多条件查询
	let page_no = 1;
	if (e.page_no > 1) {
		page_no = e.page_no;
	}
	const equip_type_name = fd.data.node.querySelector<HTMLSelectElement>('[data-zzs="equip_type_name"]').value.split(",")[0];
	const equip_name = fd.data.node.querySelector<HTMLInputElement>('[data-zzs="equip_name"]').value;
	const fixed_assets_type = fd.data.node.querySelector<HTMLSelectElement>('[data-zzs="fixed_assets_type"]').value;

	const res = await nodejs<{ rs: Array<{}>, c: number }>('device-management/zj-000001/s001', {
		filter: {
			equip_type_name,
			equip_name,
			fixed_assets_type,
			page_no
		}

	});
	for (const v in res.rs) {
		const s = res.rs[v] as { _id: string, productid: string, equip_type_name: string, equip_type_no: string, equip_internal_no: string, equip_no: string, equip_name: string, equip_description: string, equipment_state: number, fixed_assets_type: string, fixed_assets_no: string, Former_equip_no: string, transfer_time: string, transfer_price: number, transfer_date: Date, manufacturer: string, manu_country: string, manu_element_no: string, manu_years: string, equip_model: string, series_no: string };
		const a = s.transfer_time;
		const b = s.manu_years;
		if (a) {
			const da = new Date(a);
			const year = da.getFullYear() + '年';
			const month = da.getMonth() + 1 + '月';
			const date = da.getDate() + '日';
			s.transfer_time = (year + month + date);
		}
		if (b) {
			const c = new Date(b);
			const y = c.getFullYear() + '年';
			const m = c.getMonth() + 1 + '月';
			const d = c.getDate() + '日';
			s.manu_years = (y + m + d);
		}
	}
	render(fd, res.rs, p003, 'p003', 'inner');
	render(fd, { pageno: page_no, total: res.c }, p005, 'p005', 'inner');


}




// import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import p001 from './p001'
// import p002 from './p002'
// import render from '@dfeidao/atom-web/render/render';

// export default async function a003(fd: IFeidaoAiBrowserComponent) {
// 	// todo
// 	const servername = fd.data.node.querySelector<HTMLInputElement>('[data-zzs="servername"]').value
// 	const pageno = 1;
// 	const res = await nodejs<{ rs: Array<Array<{}>>, c: number }>('soa-conf/zj-000005/s001', {
// 		filter: {
// 			servername
// 		},
// 		pageno
// 	});
// 	console.info(res.c);
// 	const s = res.rs;
// 	const p = 1;
// 	render(fd, s, p001, 'p001', 'inner');
// 	render(fd, { page_no: p, total: res.c }, p002, 'p002', 'inner');

// }
